<?
session_start();
if ($_SESSION['auth'] != true && $_SESSION['rule'] != "READER") {
	die('Not log in');
}
include("includes/reader_lib.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="itelement.css" rel="stylesheet" type="text/css" />
<script src="script/jquery.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready (
	function () {
		var NONE_AVAILABLE = 'ไม่มีแชนเนลที่พร้อมใช้งานขณะนี้';
		
		if($('#avail').children().length==0)
			$('#avail').text(NONE_AVAILABLE);
		//bind clicking available list 	
		$('#avail').children().click(
			function(){
				var cid = $(this).attr('id');
				var ele = $(this).text('subscribing..');
				$.get("reader_operation.php?action=subscribe&id="+cid,
					function(data){
						ele.hide(500,
						//callback function
						function(){
							ele.remove();
							if($('#avail').children().length==0)
								$('#avail').text(NONE_AVAILABLE);
						});
					} 
				);
			}
		);
		//------------------
		$('#add').click(
			function() {
				var serialize = $('form').serialize();
				$('#status').show('fast');
				$('#status').text('Wait server...');
				$.get("reader_operation.php?action=add_external_channel&" + serialize,
				function(data){
					$('#status').text(data);
					//$('#status').hide(500);
				} );
			}
		);
		//------------------
		//bind clicking unsubscribe
		$('#unsub').click(
			function(){
				var cid = $(this).attr('id');
				var ele = $(this).text('unsubscribing..');
				$.get("reader_operation.php?action=unsubscribe&id="+cid,
					function(data){
						ele.hide(500,
						//callback function
						function(){
							ele.remove();
							if($('#avail').children().length==0)
								$('#avail').text(NONE_AVAILABLE);
						});
					} 
				);
			}
		);
	}
);
</script>
<style type="text/css">
<!--
.main { padding:30px 0 0 0; }
-->
</style>
<!--[if lte IE 6]>
<style type="text/css">
.main{ padding-top:0px;}
</style>
<![endif]-->
</head>
<body>
<div class="main">
	<div id="viewer-header2">
		<table width="100%">
			<tr><td class="viewer-head-left">Available Channel</td></tr>
		</table>
	</div>
<div id="status"></div>
<ul id="avail" style="margin-bottom:30px">
<?php
$channels = getAvailableChannel($_SESSION['userdata']['username'],$_SESSION['userdata']['rank']);
if($channels != '')
foreach($channels as $c){
echo "<li id=\"".$c['id']."\">";
echo "<a href=\"#\">".$c['title']."</a>";
if($c['exLink'] != null)
	echo '&nbsp;&nbsp;<a href="#" id="unsub" style="color:#000000">unsubscribe</a>';
echo "</li>";
}
?>
</ul>
<!--<iframe src="add_ext_channel.php" width="100%" height="200"></iframe> -->
</div>
</body></html>